﻿using System;

namespace CMN.Config
{

	
	/// <summary>
    /// 基本设置类
	/// </summary>
	public class SiteConfigs
	{

        private static System.Timers.Timer siteConfigTimer = new System.Timers.Timer(60000);

        private static SiteConfigInfo m_configinfo;

		/// <summary>
        /// 静态构造函数初始化相应实例和定时器
		/// </summary>
        static SiteConfigs()
        {
            m_configinfo = SiteConfigFileManager.LoadConfig();
            siteConfigTimer.AutoReset = true;
            siteConfigTimer.Enabled = true;
            siteConfigTimer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed); 
            siteConfigTimer.Start();
        }

        private static void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            ResetConfig();
        }


        /// <summary>
        /// 重设配置类实例
        /// </summary>
        public static void ResetConfig()
        {
            m_configinfo = SiteConfigFileManager.LoadConfig();
        }


        /// <summary>
        /// 重设配置类实例
        /// </summary>
        public static void ResetRealConfig()
        {
            m_configinfo = SiteConfigFileManager.LoadRealConfig();
        }

		public static SiteConfigInfo GetSiteConfig()
		{
            return m_configinfo;
		}



        /// <summary>
        /// 保存配置实例
        /// </summary>
        /// <param name="Siteconfiginfo"></param>
        /// <returns></returns>
        public static bool SaveConfig(SiteConfigInfo siteconfiginfo)
        {
            SiteConfigFileManager acfm = new SiteConfigFileManager();
            SiteConfigFileManager.ConfigInfo = siteconfiginfo;
            return acfm.SaveConfig();
        }
		
	}
}
